package com.example.qqbotdemo.listen;

import lombok.extern.log4j.Log4j2;
import net.mamoe.mirai.Bot;
import net.mamoe.mirai.event.EventHandler;
import net.mamoe.mirai.event.events.BotInvitedJoinGroupRequestEvent;
import net.mamoe.mirai.event.events.BotOfflineEvent;
import net.mamoe.mirai.event.events.BotOnlineEvent;
import net.mamoe.mirai.event.events.BotReloginEvent;
import net.mamoe.mirai.event.events.FriendMessageEvent;
import net.mamoe.mirai.event.events.GroupMessageEvent;
import net.mamoe.mirai.event.events.MessageEvent;
import net.mamoe.mirai.event.events.NewFriendRequestEvent;
import net.mamoe.mirai.event.events.TempMessageEvent;
import net.mamoe.mirai.message.data.MessageChain;
import org.springframework.stereotype.Component;

@Log4j2
@Component
public class BotEventListen implements net.mamoe.mirai.event.ListenerHost{

    public BotEventListen(){
        log.info("MyListener");
    }


    /**
     * 全部消息监听
     * @param event
     */
    @EventHandler
    public void onMessage(MessageEvent event) {
        //全部消息监听
    }

    /**
     * 群消息监听
     * @param event
     */
    @EventHandler
    public void onGroupMessage(GroupMessageEvent event) {
        MessageChain message = event.getMessage();
        log.info("收到群消息: " + message);
        //回复
        event.getGroup().sendMessage("你好，我是机器人");
    }

    /**
     * 临时消息监听
     * @param event
     */
    @EventHandler
    public void onTempMessage(TempMessageEvent event) {
//        MessageChain message = event.getMessage();
//        log.info("收到临时消息: " + message);
    }

    /**
     * 好友消息监听
     * @param event
     */
    @EventHandler
    public void onFriendMessage(FriendMessageEvent event) {
//        MessageChain message = event.getMessage();
//        log.info("收到好友消息: " + message);
    }

    /**
     * 机器人离线事件监听
     * @param event
     */
    @EventHandler
    public void onBotOffline(BotOfflineEvent event) {
        Bot bot = event.getBot();
        log.info("机器人离线: " + bot);
    }

    @EventHandler
    public void onBotOnline(BotOnlineEvent event) {
        log.info("机器人上线: " + event.getBot());
    }

    @EventHandler
    public void onBotRelogin(BotReloginEvent event) {
        log.info("机器人重新登录: " + event.getBot());
    }

    /**
     * 好友申请信息监听
     * @param event
     */
    @EventHandler
    public void newFriendRequestEvent(NewFriendRequestEvent event) {
        log.info("收到好友申请: qq:{}; msg: {}", event.getFromId(), event.getMessage());
    }

    /**
     * 群添加申请信息监听
     * @param event
     */
    @EventHandler
    public void botInvitedJoinGroupRequestEvent(BotInvitedJoinGroupRequestEvent event) {
        log.info("收到群添加申请: 群号:{}; QQ号: {}", event.getGroupId(), event.getInvitorId());
    }

}
